import type {
  Patient,
  PatientList,
  User,
  UserInfo,
  sendType
} from '@/types/user'
import { request } from '@/utils/request'
// 手机号+密码登录的api
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('POST', 'login/password', { mobile, password })

// 根据手机号发送验证码
// type login登录register注册changeMobile更换手机号forgetPassword找回密码,bindMobile绑定三方登录，区分验证码
export const sendMobileCode = (mobile: string, type: sendType) =>
  request('get', 'code', { mobile, type })

// 手机号+验证码登录
export const loginByCode = (mobile: string, code: string) =>
  request<User>('POST', 'login', { mobile, code })
// 获取用户信息
export const getUserInfo = () => request<UserInfo>('GET', 'patient/myUser')

// 获取患者列表

export const getPatientList = () =>
  request<PatientList>('GET', 'patient/mylist')
// 添加患者
export const addPatient = (data: Patient) =>
  request('POST', 'patient/add', data)
// 编辑患者
export const updatePatient = (data: Patient) =>
  request('PUT', 'patient/update', data)
// 删除患者
export const deletePatient = (id: string) =>
  request('DELETE', `patient/del/${id}`)

// 获取个人信息
export const getPatientInfo = (id: string) =>
  request<Patient>('GET', `patient/info/${id}`)

// 携带openId校验是否直接通过三方登录

export const loginByOpenId = (data: { openId: string; source: string }) =>
  request<User>('POST', 'login/thirdparty', data)

// 绑定QQ手机号
export const bindQQMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('POST', 'login/binding', data)
